﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeBehind="Story.aspx.cs" Inherits="Nivdal.Story" StylesheetTheme="SkinFile" %>


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor"
    TagPrefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadPlaceHolder" runat="server">

    <asp:Literal ID="StyleSheetLiteral" runat="server"></asp:Literal>
    <script language="javascript" type="text/javascript">
        function redirectToStory(storyId) {
            window.location = "Story.aspx?StoryId=" + storyId;
        }

        function ToggleDivVisibility(divname) {
            if (document.getElementById(divname).style.display == 'block') {
                document.getElementById(divname).style.display = 'none'
            }
            else {
                $("#" + divname).fadeIn(200);
                document.getElementById(divname).style.display = 'block'
            }



        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:Panel ID="NewspaperDirPanel" runat="server">
        <asp:FormView ID="StoryFormView" DataSourceID="StorySqlDataSource" runat="server"
            Width="100%">

            <ItemTemplate>
                <div class="basic_element">
                <div class="red_title">
                   <asp:Label ID="StoryTitleLabel" runat="server" Text='<%# Eval("Title") %>' CssClass="white_title"/>
                </div>
                <div class="newspaperTitle">
                    <div class="tbl"><div class="tblr">
                    <div class="tblc" style="width="80%;">
                    <asp:Label ID="StoryDateLabel" runat="server" Text='<%# Eval("Date") %>' CssClass="white_title"></asp:Label>
                    &nbsp;|&nbsp;
                    <asp:HyperLink ID="AuthorHyperlink" runat="server" Text='<%# Eval("PublicName") %>'
                        NavigateUrl='<%# "~/UserPage.aspx?Id=" + Eval("Author") %>' CssClass="white_title"></asp:HyperLink>
                    &nbsp;|&nbsp;
                    <asp:HyperLink ID="RubricHyperlink" runat="server" Text='<%# Eval("RubricName") %>' CssClass="white_title"
                        NavigateUrl='<%# "~/Rubric.aspx?Id=" + Eval("RubricID") %>'></asp:HyperLink>
                    </div>
                    <div class="tblc" style="width="20%;">
                    <asp:HyperLink ID="BackLink" runat="server" NavigateUrl='<%# "~/NewsPaper.aspx?Id=" + Eval("NewspaperId") %>'
                        CssClass="yellow_title" Text="<%$ Resources:Resource, Story_BackToNewspaper %>"></asp:HyperLink>
                    </div>
                    </div>
                    </div>
                    
                </div>
                <div class="padding5">

                <div class="antiloater padding5">
                    <div class="pictureFloat rounded_corners">
                        <asp:Image ID="StoryImage" runat="server" Width="150px" AlternateText="<%$ Resources:Resource, Story_StoryImage %>"
                            ImageUrl='<%# Eval("image") %>' onerror="this.src='Images/menupicture.gif';" CssClass="rounded_corners" />
                        <br /><br />
                        <asp:Panel ID="RatingPanel" runat="server" Visible='<%# !IsRated() %>'>
                    
                            <asp:Label ID="Label1" runat="server" Text="<%$ Resources:Resource, Story_RateThisStory %>"
                                Visible='<%# !IsRated() %>' SkinID="InfoLabel"></asp:Label>
                            <%--<asp:Label ID="Label2" runat="server" Text="<%$ Resources:Resource, Story_AlreadyRated %>"
                                Visible='<%# IsRated() %>' SkinID="InfoLabel"></asp:Label>--%>
                            &nbsp;&nbsp;

                            <asp:Rating ID="StoryRating1" runat="server"  CurrentRating='<%#  UserStoryRatingValue() %>'
                                MaxRating="5" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar" 
                                FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar" Tag="99"
                                OnChanged="StoryRating_Changed" BehaviorID="RatingBehavior1" Width="80px" ReadOnly='<%# IsRated() %>'
                                Height="16px">
                            </asp:Rating>

                   
                            <asp:Label ID="CounterLabel" runat="server" CssClass="reg_text"></asp:Label>
                            <br />
                            <span id="lblResponse" class="reg_text"></span>
                                            
                    
                                <script type="text/javascript">
                                    Sys.Application.add_load(function () {

                                        $find("RatingBehavior1").add_EndClientCallback(function (sender, eventArgs) {
                                            var responseTag = $get('ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_StoryFormView_CounterLabel');
                                            responseTag.innerHTML = eventArgs.get_CallbackResult();
                                            var elt = $find('RatingBehavior1').get_element();
                                            if ($find('RatingBehavior1')._stars) {
                                                for (var i = 0; i < $find('RatingBehavior1')._stars.length; i++) {

                                                    var starElement = $find('RatingBehavior1')._stars[i];
                                                    $removeHandler(starElement, 'click', $find('RatingBehavior1')._starClickHandler);

                                                    $removeHandler(starElement, 'mouseover', $find('RatingBehavior1')._starMouseOverHandler);
                                                }
                                            }
                                            $removeHandler(elt, 'mouseout', $find('RatingBehavior1')._mouseOutHandler);

                                            $removeHandler(elt, "keydown", $find('RatingBehavior1')._keyDownHandler);
                                            window.onunload = function () {
                                                $find('RatingBehavior1')._stars = null;
                                            }

                                        });
                                    });
                            </script>
                        </asp:Panel>
                        <asp:Image ID="EvaluationsImage" runat="server" ImageUrl='<%# "~/Images/NewsPaper/" + Eval("Evaluation") + "star.png" %>' Visible='<%# IsRated() %>'
                         ToolTip='<%# Resources.Resource.Newspaper_StoryRatingTitlePart1 + " " + Eval("EvaluationCount") + " " +  Resources.Resource.Story_RightSideRatedStory + " " + Eval("ExactEvaluation") %>' />
                
                    </div>
                </div>            
              
                <asp:Label ID="TextLabel" runat="server" Text='<%# StoryBody(Eval("Text")) %>' />
                        

                <br /><hr /><br />
                <asp:Label ID="TalkbacksTitleLabel" runat="server" Text="<%$ Resources:Resource, Story_Comments %>"
                    CssClass="NewspaperStoryTitle"></asp:Label>
                <br />
                <asp:UpdatePanel ID="TalkBacksPanel" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Repeater ID="TalkBacksRepeater" runat="server" DataSourceID="TalkBacksSqlDataSource"
                            OnItemCommand="DeleteComment">
                            <ItemTemplate>
                                <div class="NewspaperFonts">
                                    <asp:Label ID="TalkbackNumberLabel" runat="server" CssClass="NewspaperSmallBlueTitle"
                                        Text='<%# Eval("Number") + ". " %>' onclick='<%# "javascript:ToggleDivVisibility(\"Talkbackdiv" + Eval("Id") + "\")" %>'></asp:Label>
                                    <asp:Label ID="TalkbackTitleLabel" runat="server" Text='<%# Eval("Title") %>'
                                    onclick='<%# "javascript:ToggleDivVisibility(\"Talkbackdiv" + Eval("Id") + "\")" %>'></asp:Label>
                                    &nbsp;
                                    <asp:HyperLink ID="UserHyperlink" runat="server" Text='<%# "(" + Eval("PublicName") + ")" %>'
                                        NavigateUrl='<%# "~/UserPage.aspx?Id=" + Eval("UserId") %>' SkinID="GreenTitleHyperLink"></asp:HyperLink>
                                    ,&nbsp;
                                    <asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
                                    
                                    <div id='<%# "Talkbackdiv" + Eval("Id") %>' style="display: none; padding: 10px;"
                                        class="NewspaperFonts">
                                        <table cellpadding="0" cellspacing="0" width="100%">
                                            <tr>
                                                <td style="width: 90%">
                                                    <asp:Label ID="TalkBackTextLabel" runat="server" Text='<%# Eval("Text").ToString().Replace("\r\n", "<br /> ") %>'
                                                        SkinID="GridLabel"></asp:Label>
                                                </td>
                                                <td style="width: 10%;">
                                                    <asp:ImageButton ID="DeleteButton" runat="server" CommandName="Delete" CommandArgument='<%# Eval("Id") %>'
                                                        ImageUrl="~/Images/Icons/delete.png" Visible='<%# CanDeleteComments(Eval("UserId")) %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>
                        <asp:Label ID="NoTalkBacksLabel" runat="server" Text="<%$ Resources:Resource, Story_NoTalkBacksYet %>"
                            SkinID="InfoLabel"></asp:Label>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <br />
                <asp:Panel ID="AddTalkbackPanel" runat="server">
                    <table>
                        <tr>
                            <td>
                                <asp:Label ID="AddTalkBackLabel" runat="server" Text="<%$ Resources:Resource, Story_AddTalkBack %>"
                                    CssClass="NewspaperSmallBlueTitle"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="lblMimimumLength" runat="server" Text="" SkinID="ErrorLabel"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:TextBox ID="AddTalkBackTitleTextBox" MaxLength="150" runat="server" Width="300px"
                                    CssClass="NewspaperSmallBlueTitle"></asp:TextBox>
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="<%$ Resources:Resource, Story_MissingTitle %>"
                                    ControlToValidate="AddTalkBackTitleTextBox" SetFocusOnError="True" ValidationGroup="NewTalkBack"></asp:RequiredFieldValidator>
                                <asp:TextBoxWatermarkExtender ID="AddTalkbackExtender" runat="server" TargetControlID="AddTalkBackTitleTextBox"
                                    WatermarkText="<%$ Resources:Resource, Global_Title %>">
                                </asp:TextBoxWatermarkExtender>
                            </td>
                        </tr>
                        <tr>
                            <td>
                            </td>
                            <td>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <CustomControls:TextArea ID="TalkBackTextTextBox" MaxLength="400" runat="server"
                                    Rows="7" Height="100px" Width="300px" CssClass="NewspaperSmallBlueTitle" TextMode="MultiLine"></CustomControls:TextArea>
                                <asp:TextBoxWatermarkExtender runat="server" ID="TalkbackTextExtender" TargetControlID="TalkBackTextTextBox"
                                    WatermarkText="<%$ Resources:Resource, Story_TalkBack %>">
                                </asp:TextBoxWatermarkExtender>
                                <br />
                                <br />
                                <asp:Button ID="AddTalkBackButton" runat="server" ValidationGroup="NewTalkBack" OnClick="AddTalkBackButton_Click"
                                    CssClass="GreenSmallButtonStyle" Text="<%$ Resources:Resource, Story_AddTalkBack %>" />
                            </td>
                            <td style="vertical-align: bottom;">
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
                <br />
                <br />
                <br />
                <asp:HyperLink ID="EditStoryHyperLink" runat="server" Visible="false" CssClass="PageNameContentStyle"
                    Text="<%$ Resources:Resource, Story_EditStory %>"></asp:HyperLink>
                &nbsp;&nbsp;
                <asp:Button ID="ApproveStoryButton" runat="server" Text="<%$ Resources:Resource, Story_ApproveStory %>"
                    Visible="false" CommandName="Submit" message="<%$ Resources:Resource, Story_AreYousureApprove %>"
                    CssClass="GreenSmallButtonStyle" OnClientClick='return confirm(this.getAttribute("message"))'
                    OnClick="ApproveStoryButton_click" />
                &nbsp;&nbsp
                <asp:Button runat="server" ID="DeleteStoryButton" CssClass="GreySmallButtonStyle"
                    Message="<%$ Resources:Resource, Story_AreYousureDeleteStory %>" OnClientClick='return confirm(this.getAttribute("Message"))'
                    Text="<%$ Resources:Resource, Global_Delete %>" OnClick="DeleteStory" Visible='<%# DeleteVisible(Eval("IsDeleted")) %>' />
                <asp:Panel ID="StoryDeletedPanel" runat="server" Visible='<%# IsDeletedVisible(Eval("IsDeleted")) %>'>
                    <asp:Label ID="StoryDeletedLabel" runat="server" Text="<%$ Resources:Resource, Story_StoryIsDeleted %>"
                        SkinID="GridLabel"></asp:Label>
                    <asp:Button ID="UndeleteButton" runat="server" Text="<%$ Resources:Resource, Story_UndeleteButtonText %>"
                        OnClick="UndeleteStory" CssClass="GreenSmallButtonStyle" />
                </asp:Panel>
                </div>
                </div>
            </ItemTemplate>
        </asp:FormView>
        <%--<asp:FormView ID="QuickNavigationFormView" runat="server" DataSourceID="QuickNavigationDataSource" Width="70%">
    <ItemTemplate>
    <div class="NewsPaperTitleTopStyle">
        <table cellpadding="0" cellspacing="2" style="vertical-align:middle;">
        <tr><td>
            <asp:Image ID="ArrowsImage" runat="server" ImageUrl="~/Images/NewsPaper/arrows.jpg" />
        </td><td>
            <div style="width:100px; padding-left:10px; padding-right:10px; white-space:nowrap;">
            <asp:Label ID="CategoriesTitleLabel" runat="server" 
            Text="<%$ Resources:Resource, Story_MoreInRubric %>"></asp:Label>
            <asp:HyperLink ID="RubricHyperlink" runat="server" NavigateUrl='<%# "~/Rubric.aspx?Id=" + Eval("RubricId") %>'
             Text='<%# Eval("RubricName") + " (" + Eval("CountMoreStories") + " " + Resources.Resource.Story_MoreStories + ")" %>'></asp:HyperLink>
            </div>
        </td></tr>
        </table>    
    <div class="NewspaperTitleInnerStyle">
        <asp:HiddenField ID="NewspaperIdHiddenField" runat="server" Value='<%# Eval("NewspaperId") %>' />
        <asp:Repeater ID="RubricsRepeater" runat="server" DataSourceID="RubricsDataSource">
        <ItemTemplate>                    
            <asp:HyperLink ID="RubricHyperlink" runat="server" Text='<%# Eval("RubricName") %>'
            NavigateUrl='<%# "~/Rubric.aspx?Id=" + Eval("rubricId") %>'></asp:HyperLink>                    
        </ItemTemplate>
        <SeparatorTemplate>&nbsp;|&nbsp;</SeparatorTemplate>
        </asp:Repeater>
        <asp:SqlDataSource ID="RubricsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="Nivdal_GetNewsPaperRubrics" SelectCommandType="StoredProcedure">
            <SelectParameters>
                
                <asp:ControlParameter ControlID="NewspaperIdHiddenField" Type="Decimal" Name="NewspaperId" PropertyName="Value"/>                
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </div>
    </ItemTemplate>    
    </asp:FormView>--%>
        <asp:SqlDataSource ID="TalkBacksSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="Nivdal_ShowStoryTalkBacks" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:QueryStringParameter Name="StoryId" QueryStringField="StoryId" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="StorySqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="Nivdal_ShowStory" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:QueryStringParameter Name="StoryId" QueryStringField="StoryId" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <%--<asp:SqlDataSource ID="QuickNavigationDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="Nivdal_GetRubricInfoForStory" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:QueryStringParameter Name="StoryId" QueryStringField="StoryId" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>--%>
    </asp:Panel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageNamePlaceHolder" runat="server">
    <asp:Label ID="PageNameLabel" runat="server" Text="<%$ Resources:Resource, Newspaper_PageName %>"
        CssClass="PageNameContentStyle"></asp:Label>
</asp:Content>
